package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbSellerMapper;
import com.bw1806.pojo.TbSeller;
import com.bw1806.pojo.TbSellerExample;
import com.bw1806.sellergoods.service.TbSellerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbSellerServiceImpl implements TbSellerService {

    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Override
    public List<TbSeller> findAll() {
        return tbSellerMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbSeller> pagelist(TbSeller tbSeller,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbSellerExample example=new TbSellerExample();

        TbSellerExample.Criteria criteria = example.createCriteria();

        if(tbSeller!=null){
            //if(tbSeller.getName()!=null && tbSeller.getName().length()>0){
            //    criteria.andNameLike("%"+tbSeller.getName()+"%");
           // }
        }

        Page<TbSeller> page= (Page<TbSeller>) tbSellerMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbSeller tbSeller) {
        String id = tbSeller.getSellerId();
        /*if(id != null && id !=0){
            tbSellerMapper.updateByPrimaryKey(tbSeller);
        } else{
            tbSellerMapper.insert(tbSeller);
        }*/
    }

    @Override
    public TbSeller getById(String id) {
        return tbSellerMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(String[] ids) {
       for(String id : ids){
            tbSellerMapper.deleteByPrimaryKey(id);
        }
        //tbSellerMapper.deletebth(ids);
    }
}
